package com.msg.xml;

import java.util.ArrayList;

/**
 * This class get the information associate with price code table and
 * adding them into the price code table
 * @author jeson9603
 *
 */
public class PriceCode_Manipulator extends Table_Manipulator {

	private ArrayList<String> eventCode;
	private ArrayList<String> priceLevel;
	private ArrayList<ArrayList<String>> priceTable;
	
	public PriceCode_Manipulator(Property prop) {
		super(prop);
		eventCode = new ArrayList<String>();
		priceLevel = new ArrayList<String>();
		priceTable = new ArrayList<ArrayList<String>>();
	}
	
	/**
	 * read all the contents from price code table
	 * and get a list of event, a list of price levels and a table of prices
	 */
	@Override
	protected String getSpecificData() {
		XMLhandler.moveCursorForward();
		while(true) {
			ArrayList<String> content = XMLhandler.getDataList();
			//read the end of price code table
			if(content.get(0).compareTo("") == 0)
				break;
			if(content.get(1).compareTo(" -------->") == 0)
				continue;
			eventCode.add(content.get(0));
			priceLevel.add(content.get(1));
			ArrayList<String> prices = new ArrayList<String>();
			for(int i = 0; i < prop.getTICKETLEVEL_NUM(); i++) {
				prices.add(content.get(4 + i));
			}
			priceTable.add(prices);
		}
		return null;
	}

	/**
	 * invoking the update method in TicketType_Manipulator, PriceLevel_Manipulator and Price_Manipulator
	 * to add the ticket type information, price level information and price information to database
	 */
	@Override
	protected String update() {
		Table_Manipulator tic = new TicketType_Manipulator(prop);
		Table_Manipulator prc = new PriceLevel_Manipulator(prop);
		TicketGroup_Manipulator tgroup = new TicketGroup_Manipulator(prop);
		Table_Manipulator prcs = new Price_Manipulator(prop);
		int length = eventCode.size();
		for(int i = 0; i < length; i++) {
			//pushing the data to different manipulators so that they can check these data in different table
			//or update them
			tic.pushData(eventCode.get(i));
			prc.pushData(priceLevel.get(i));
			String ticketGroup[] = {eventCode.get(i), priceLevel.get(i)};
			tgroup.pushData(ticketGroup);
			prcs.pushData(priceTable.get(i));
			
			tic.update();
			prc.update();
			tgroup.update();
			prcs.update();
		}
		return null;
	}
	
	
	@Override
	protected void pushData(Object o) {
	}

}
